﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SuperMap.Desktop;
using SuperMap.Desktop.UI;
using SuperMap.Data;
using SuperMap.UI;
using SuperMap.Analyst;
using SuperMap.Analyst.SpatialAnalyst;
using SuperMap.Mapping;



namespace DesktopPlugin1
{
    class MyCtrlAction : CtrlAction
    {
        #region  定义变量

        private Workspace k_workspace = null;//新建工作空间
        public string dataSourceName = null;//获得数据源名
        private DatasourceConnectionInfo datasourceConnectInfo = new DatasourceConnectionInfo();//定义数据源连接信息
        private MyControl k_DensityForm = null;//密度分析窗口
        
        #endregion

        public MyCtrlAction(IBaseItem caller, IForm formClass)
            : base(caller, formClass)
        {

        }

        override public void Run()
        {
            //To do your work.
            //Example:

            //跳出dockbar
            IDockBar dockBarManage = SuperMap.Desktop.Application.ActiveApplication.MainForm.DockBarManager[typeof(MyControl)];
            MyControl ctrl = (MyControl)dockBarManage.Control;
            try
            {
                ctrl.clearData();//清空原有数据
            }
            catch { }
            dockBarManage.Visible = true;

            IBaseItem baseItem = this.Caller;
            k_DensityForm = (MyControl)dockBarManage.Control;//新建密度分析窗体

            try
            {
                MapControl k_mapControl = new MapControl();

                //获取当前图层
                IFormMap mapWindow = FormClass as IFormMap;
                k_mapControl.Map.Workspace = mapWindow.MapControl.Map.Workspace;
                k_workspace = k_mapControl.Map.Workspace;//获取当前工作空间
                k_DensityForm.environment(k_workspace, k_mapControl);//传入当前工作空间和图层
            }
            catch { }

        }

        //获得当前地图窗口对象
        public MapControl MapControl
        {
            get
            {
                MapControl mapControl = null;
                try
                {
                    mapControl = (SuperMap.Desktop.Application.ActiveForm as IFormMap).MapControl;
                }
                catch { }
                return mapControl;
            }
        }
    }
}
